<?php
define('EZSITETPL_SOAP', 1);
include_once('config.php');
include_once('func_utils.php');
define('DS', DIRECTORY_SEPARATOR);
define('ROOT', dirname(__FILE__));
define('P_TPL', realpath(ROOT.DS.'../..'.DS.'templates/template_jingjian'));
define('PRE_SCRSHOT_URL', _urlprefix().URL_SCRSHOT);
define('PRE_DOWNLOAD_URL', _urlprefix().URL_DOWNLOAD);

$db = mysqli_connect(DB_HOST, DB_USER, DB_PASS);
mysqli_set_charset($db, DB_CHAR);
mysqli_select_db($db, DB_NAME);


$cateid = $_GET['cateid'];
$ezsite_uid = $_GET['ezsite_uid'];
$level = $_GET['level'];
$level=2;
$tpls = array();
$cateid = mysqli_real_escape_string($db, $cateid);
$ezsite_uid = mysqli_real_escape_string($db, $ezsite_uid);
$level = mysqli_real_escape_string($db, $level);

$sql = "SELECT `ezsite_new_templates`.*, `ezsite_template_new_categories`.`name` AS category,"
        ." `purchased_templates`.`purchase_time` FROM `ezsite_template_new_categories`"
        ." RIGHT JOIN (`ezsite_new_templates` LEFT JOIN `purchased_templates` ON"
        ." `ezsite_new_templates`.`id`=`purchased_templates`.`ezsite_template_id`) ON"
        ." `ezsite_template_new_categories`.`id`=`ezsite_new_templates`.`ezsite_template_category_id` WHERE"
        ." (`purchased_templates`.`ezsite_uid`='$ezsite_uid' OR `ezsite_new_templates`.`isfree`='1')"
//        ." AND `ezsite_new_templates`.`ezsite_template_category_id`='$cateid'"
        ." AND `ezsite_new_templates`.`i_level`='$level' order by i_order desc";
$rs = mysqli_query($db, $sql);
if ($rs && mysqli_num_rows($rs) > 0) {
	while ($row = mysqli_fetch_assoc($rs)) {
		$row['screenshot_url'] = PRE_SCRSHOT_URL.'/'.$row['screenshot'];
		$row['package_url'] = PRE_DOWNLOAD_URL.$row['id'];
        $tpls[] = $row;
    }
}
mysqli_free_result($rs);

echo serialize($tpls);
?>